<template>
  <view class="my-page">
    <view class="base-msg-warpper">
      <view class="base-msg-card card">
        <view class="lvl-box">
          <view class="user-avatar">
            <ai-avatar :src="avatarUrl" size="xxl"></ai-avatar>
          </view>
          <view class="lvl-warpper">
            <view class="user-nick">
              <text class="name">{{nickName}}</text>
              <view class="lvl">
                <ai-user-level level="黄金会员" type="gold"></ai-user-level>
              </view>
            </view>
            <view class="lvl-tag">免费会员 lv.1</view>
          </view>
        </view>
        <view class="base-info">梦想的脚步从不停止，行无止境</view>
        <view class="base-info">
          <view class="stat-item">
            <text class="title">被收藏</text>
            <text class="num">{{beCollectCnt}}</text>
          </view>
          <view class="stat-item">
            <text class="title">收藏</text>
            <text class="num">{{collectCnt}}</text>
          </view>
          <view class="stat-item">
            <text class="title">获赞</text>
            <text class="num">{{beAgreeCnt}}</text>
          </view>
          <view class="stat-item">
            <text class="title">赞过</text>
            <text class="num">{{agreeCnt}}</text>
          </view>
        </view>
      </view>
    </view>
   <!-- <view class="account-card card">
      <view class="account-info">
        <text class="title">账户总览</text>
        <view class="ammount-box">
          <view class="ammount-item">
            <text class="item-title">剩余可规划次数</text>
            <text class="item-number">9</text>
          </view>
          <view class="ammount-item">
            <text class="item-title">免费修改次数</text>
            <text class="item-number">9</text>
          </view>
        </view>
      </view>
      <view class="action-box">
        <text class="action-tip">分享行程赢修改额度</text>
        <text class="action-tip">成为付费会员</text>
      </view>
    </view> -->
    
    <view class="list-actions">
      <tp-list-card :items="qkOptions" @itemClick="onQkSelected"></tp-list-card>
    </view>
    
    <view class="list-actions">
      <tp-list-card :items="aboutList"></tp-list-card>
    </view>
  </view>
</template>

<script>
  
  import { mapState } from "vuex"
  
  export default {
    data() {
      return {
        planCnt: 0,
        agreeCnt: 0,
        beAgreeCnt: 0,
        collectCnt: 0,
        beCollectCnt: 0,
        qkOptions: [{
          icon: "icon-plan",
          title: "我的规划",
          right: true,
          page: "my_plan"
        },{
          icon: "icon-collect",
          title: "我的收藏",
          right: true,
          page: "my_collect"
        }],
        aboutList: [
          {
            title: "相关问题QA",
            right: true
          },{
            title: "加入我们",
            right: true
          }
        ]
      };
    },
    computed: {
      ...mapState({
        nickName: state => state.user.nickName,
        avatarUrl: state => state.user.avatarUrl
      })
    },
    onLoad() {
      this.init()
    },
    methods: {
      init() {
        this.myStat()
      },
      myStat() {
        let url = this.$urls.getApi("myStat")
        this.$get(url).then(res => {
          let stat = res.module
          this.agreeCnt = stat.agreeCnt
          this.beAgreeCnt = stat.beAgreed
          this.collectCnt = stat.collectCnt
          this.beCollectCnt = stat.beCollected
        })
      },
      onQkSelected(item) {
        let page = item.page
        let nav2url = `/pages/my/${page}`
        uni.navigateTo({
          url: nav2url
        })
      }
    }
  }
</script>

<style lang="scss">
  @import "@/styles/_var.scss";

  $bg-2: lighten(#32a2f1, 20%);
  $bg-3: lighten(#32a2f1, 50%);

  .my-page {
    background: linear-gradient(180deg, #32a2f1 10px, $bg-2 45px, $bg-3 120px, $white 300px, $white 100%);
    min-height: 100vh;
    box-sizing: border-box;
  }
  
  .base-msg-warpper {
    padding: $gutter;
  }
  
  .card {
    position: relative;
    background-color: var(--white);
    box-shadow: $shadow-1;
    padding: $gutter;
    border-radius: $card-border-radius;
    color: #333;
  }

  .base-msg-card {
    .lvl-box {
      .user-avatar {
        position: absolute;
        top: -$gutter;
        left: $gutter;
      }
      
      .lvl-warpper {
        margin-left: 68px;
        margin-top: -6px;
      }
      
      .user-nick {
        display: flex;
        align-items: center;
        .name {
          font-size: 18px;
          font-weight: $font-weight-bold;
          color: #333;
        }
        .lvl {
          margin-left: 6px;
        }
      }
      .lvl-tag {
        display: inline-block;
        background-color: lighten($green, 35%);
        border-radius: 6px 2px 6px 2px;
        padding: 0 4px;
        font-size: $font-size-xs;
        color: $green;
      }
    }
    
    .base-info {
      margin-top: 6px;
      font-size: $font-size-sm;
      font-weight: 300;
      display: flex;
    }
    .stat-item {
      position: relative;
      padding: 0 $gutter;
      
      .title {
      }
      .num {
        padding-left: 4px;
        font-weight: $font-weight-bold;
        color: var(--gray-1);
      }
      
      &:last-child {
        padding-right: 0;
      }
      
      &:first-child {
        padding-left: 0;
      }
      
      &:not(:last-child)::after {
        content: " ";
        position: absolute;
        right: 0;
        top: 50%;
        bottom: 0;
        width: 1px;
        height: 60%;
        transform: translateY(-50%);
        border-right: 1px solid var(--gray-4);
      }
    }
  }

  .account-card {
    margin: 0 $gutter;
    
    .account-info {
      margin: -$gutter;
      border-radius: $card-border-radius;
      padding: $gutter;
      background: linear-gradient(90deg, #FFF4D2, #FFECB6);
      display: flex;
      flex-direction: column;
      color: #663300;
      
      .title {
        font-size: $font-size-lg;
        font-weight: $font-weight-bold;
      }
      
      .ammount-box {
        margin-top: $gutter;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .ammount-item {
          display: flex;
          flex-direction: column;
          .item-title {
            color: #A88100;
            font-size: $font-size-md;
          }
          .item-number {
            padding-top: 2px;
            font-size: $font-size-lg * 1.3;
          }
        }
      }
    }
    
    .action-box {
      position: relative;
      display: flex;
      margin-top: $gutter * 2;
      padding: 0 $gutter;
      
      &:before {
        content: "";
        position: absolute;
        top: 50%;
        left: 0;
        height: 6px;
        width: 6px;
        border-radius: 50%;
        background-color: var(--brand-2);
        transform: translateY(-50%);
      }
      
      .action-tip {
        position: relative;
        display: block;
        padding: 0 $gutter;
        
        &:not(:last-child):after {
          content: "";
          position: absolute;
          top: 50%;
          right: -2px;
          height: 60%;
          width: 2px;
          border-left: 2px solid var(--gray-5);
          transform: translateY(-50%);
        }
        
        &:first-child {
          padding-left: 0;
        }
        &:last-child {
           padding-right: 0;
        }
      }
    }
  }
  
  .list-actions {
    margin: $gutter;
  }

</style>